<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>TestNetty</title>
    <script type="text/javascript">
        var socket;
        if(!window.WebSocket){
            window.WebSocket = window.MozWebSocket;
        }
        if(window.WebSocket){
            // 服务器ip
            // var path = "120.25.193.197";

            // 本地ip
            // var path = "localhost";
            socket = new WebSocket("ws://120.25.193.197:1024/channel");
            socket.onmessage = function(event){
                var ta = document.getElementById('responseText');
                ta.value += event.data+"\r\n";
            };
            socket.onopen = function(event){
                var ta = document.getElementById('responseText');
                ta.value = "已连接";
            };
            socket.onclose = function(event){
                var ta = document.getElementById('responseText');
                ta.value = "已关闭";
            };
        }else{
            alert("您的浏览器不支持WebSocket协议！");
        }
        function send(message){
            if(!window.WebSocket){return;}
            if(socket.readyState == WebSocket.OPEN){
                socket.send(message);
            }else{
                alert("WebSocket 连接没有建立成功！");
            }
        }
    </script>
</head>
<body>
<form onSubmit="return false;">
    <hr color="black" />
    <h3>客户端发送的信息</h3>
    <label>名字</label><input type="text" name="uid" value="MO_or" /> <br />
    <label>内容</label><input type="text" name="message" value="你好！我是MO_or" /> <br />
    <br /> <input type="button" value="点击发送" onClick="send(this.form.uid.value+':'+this.form.message.value)" />
    <hr color="black" />
    <h3>服务端返回的应答消息</h3>
    <textarea id="responseText" style="width: 900px;height: 300px;"></textarea>
</form>
</body>
</html>